package com.controller;

import com.constance.Code;
import com.entity.Book;
import com.exception.BusinessException;
import com.resp.Result;
import com.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/books")
public class BookController {

    @Autowired
    private BookService bookService;

    @GetMapping("/{id}")
    public Result selectById(@PathVariable Integer id) throws ArithmeticException{
        Book book = bookService.selectById(id);
        return new Result(Code.GET_OK,book,"查询成功");
    }

    @GetMapping("/test")
    public Result test() throws BusinessException {
        Boolean test = bookService.test();
        return new Result(Code.GET_OK,"测试成功");
    }

}
